package org.swqsbssddqs.shortlink.admin.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.swqsbssddqs.shortlink.admin.common.convention.result.Result;
import org.swqsbssddqs.shortlink.admin.common.convention.result.Results;
import org.swqsbssddqs.shortlink.admin.dto.req.GroupCreateReqDTO;
import org.swqsbssddqs.shortlink.admin.dto.req.GroupSortReqDTO;
import org.swqsbssddqs.shortlink.admin.dto.req.GroupUpdateReqDTO;
import org.swqsbssddqs.shortlink.admin.dto.resp.GroupListRespDTO;
import org.swqsbssddqs.shortlink.admin.service.GroupService;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class GroupController {
    private final GroupService groupService;

    @PostMapping("/api/short-link/admin/v1/group")
    public Result<String> createGroup(@RequestBody GroupCreateReqDTO param){
        return Results.success(groupService.create(param.getName()));
    }
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<GroupListRespDTO>> listGroup(){
        return Results.success(groupService.listGroup());
    }


    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody GroupUpdateReqDTO groupUpdateReqDTO){
        groupService.updateGroup(groupUpdateReqDTO);
        return Results.success();
    }

    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Boolean> deleteGroup(@RequestParam String gid){
        return Results.success(groupService.deleteGroup(gid));
    }

    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> updateGroup(@RequestBody List<GroupSortReqDTO> groupSortReqDTOList){
        groupService.sortGroup(groupSortReqDTOList);
        return Results.success();
    }
}
